use core::{cell::UnsafeCell, ffi::c_void, mem::MaybeUninit};

mod message_queue;

pub use message_queue::MessageQueue;
pub use message_queue::mq_size;

mod event_flags;
pub use event_flags::EventFlags;
pub use event_flags::EventFlagsValue;

mod mutex;
pub use mutex::Mutex;
pub use mutex::{MutexValue, MutexGuard};

mod thread;
pub use thread::Task;
pub use thread::Thread;

mod msg_queue;
pub use msg_queue::MsgQueue;


mod arc;
pub use arc::Arc;

#[macro_export]
macro_rules! message_queue {
    ($name: ident, $t: ty, $msg_count: expr) => {
        static $name: MessageQueue<$t, $msg_count, { mq_size::<$t>($msg_count) }> = MessageQueue::uninit();
    };
}



#[repr(align(8))]
struct StaticMem<const SIZE: usize> {
    _buf: UnsafeCell<MaybeUninit<[u8; SIZE]>>,
}

impl <const SIZE: usize> StaticMem<SIZE> {

    pub const fn const_new() -> Self {
        Self { _buf: UnsafeCell::new(MaybeUninit::uninit()) }
    }

    pub const fn as_ptr(&self) -> *mut c_void {
        self as *const Self as _
    }
}

#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum Error {
    Timeout,
    Resource,
}


